package com.zhenmaitang.clinic_sys.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 系统菜单实体类 - 菜单权限管理
 */
@Schema(description = "系统菜单实体", example = "菜单权限信息")
public class SysMenu implements Comparable<SysMenu> {
    @Schema(description = "菜单ID", example = "1")
    private Integer id;
    
    @Schema(description = "菜单名称", example = "患者管理", requiredMode = Schema.RequiredMode.REQUIRED)
    private String menuName;
    
    @Schema(description = "菜单路径", example = "/patient/list")
    private String path;
    
    @Schema(description = "前端组件路径", example = "views/patient/index.vue")
    private String component;
    
    @Schema(description = "菜单图标", example = "el-icon-user")
    private String icon;
    
    @Schema(description = "排序号", example = "1", defaultValue = "0")
    private Integer sortOrder;
    
    @Schema(description = "父菜单ID", example = "0", defaultValue = "0")
    private Integer parentId;
    
    @Schema(description = "菜单类型", example = "MENU", allowableValues = {"MENU", "BUTTON", "API"})
    private String menuType;
    
    @Schema(description = "重定向", example = "/patient/list")
    private String redirect;
    
    @Schema(description = "权限标识", example = "patient:view")
    private String permissionCode;
    
    @Schema(description = "是否可见", example = "true", defaultValue = "true")
    private Boolean visible;
    
    @Schema(description = "是否启用", example = "true", defaultValue = "true")
    private Boolean enabled;
    
    @Schema(description = "创建时间", example = "2024-01-15 10:30:00")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    
    @Schema(description = "更新时间", example = "2024-01-15 14:20:00")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    
    // 非数据库字段，用于存储子菜单

    @Schema(description = "子菜单列表", type = "array", format = "json")
    private List<SysMenu> children;
    
    public SysMenu() {}
    
    public SysMenu(String menuName, String path, String component, String icon, 
                   Integer sortOrder, Integer parentId, String menuType, 
                   String permissionCode, Boolean visible, Boolean status) {
        this.menuName = menuName;
        this.path = path;
        this.component = component;
        this.icon = icon;
        this.sortOrder = sortOrder;
        this.parentId = parentId;
        this.menuType = menuType;
        this.permissionCode = permissionCode;
        this.visible = visible;
        this.enabled = true;
    }
    @Override
    public int compareTo(SysMenu sysMenu) {
        return Integer.compare(this.sortOrder, sysMenu.sortOrder);
    }

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public String getMenuType() {
        return menuType;
    }

    public void setMenuType(String menuType) {
        this.menuType = menuType;
    }

    public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }

    public Boolean getVisible() {
        return visible;
    }

    public void setVisible(Boolean visible) {
        this.visible = visible;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public List<SysMenu> getChildren() {
        return children;
    }

    public void setChildren(List<SysMenu> children) {
        this.children = children;
    }

    @Override
    public String toString() {
        return "SysMenu{" +
                "id=" + id +
                ", menuName='" + menuName + '\'' +
                ", path='" + path + '\'' +
                ", component='" + component + '\'' +
                ", icon='" + icon + '\'' +
                ", redirect='" + redirect + '\'' +
                ", sortOrder=" + sortOrder +
                ", parentId=" + parentId +
                ", menuType='" + menuType + '\'' +
                ", permissionCode='" + permissionCode + '\'' +
                ", visible=" + visible +
                ", enabled=" + enabled +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}